package com.omazan.nativeClient;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;

import com.omazan.db.HandleAdmins;
import com.omazan.db.HandleCustomers;
import com.omazan.db.HandleEmployees;
import com.omazan.db.HandleUsers;
import com.omazan.db.models.Administrator;
import com.omazan.db.models.Customer;
import com.omazan.db.models.Employee;
import com.omazan.db.models.User;
import com.omazan.utils.OmazanException;

public class UserDisplayOperations {
	BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
	
	public int userDisplayLogin(int type) throws OmazanException, IOException{
		
		User user = new User();
		
		System.out.println("Enter User name");
		user.setUserName(input.readLine());
		System.out.println("Enter User password");
		user.setPassword(input.readLine());
		
		user.setActive(true);
		user.getUserType().setUserTypeId(type);
		
		new HandleUsers().insertUser(user);
		//System.out.println(user.getUserId());
		return user.getUserId();
	}

	public void usertypeDisplayOperations() throws OmazanException, IOException {
		int o=0;
		while (o==0) {
			System.out.println("DISPLAY OPTIONS:");
			System.out.println("1.Customer");
			System.out.println("2.Employee");
			System.out.println("3.Administrator");
			System.out.println("4.Exit to Previous Menu");
			String userInput = input.readLine();
			int operation = Integer.parseInt(userInput);
			switch (operation) {
			case 1:

				HandleCustomers hcust1 = new HandleCustomers();
				
				List<Customer> listofCustomers = hcust1
						.readAllCustomersFromDB();

				for (Customer eachCustomer : listofCustomers) {
					System.out.println(eachCustomer.getCustomerId() + " | "
							+ eachCustomer.getLastName() + " | "
							+ eachCustomer.getFirstName() + " | "
							+ eachCustomer.getHouseNo() + "|"
							+ eachCustomer.getStreet() + "|"
							+ eachCustomer.getCity() + "|"
							+ eachCustomer.getState() + "|"
							+ eachCustomer.getCountry() + "|"
							+ eachCustomer.getMobileNo() + "|"
							+ eachCustomer.getEmail());

				}
				break;
			case 2:
				HandleEmployees hemp1 = new HandleEmployees();
				List<Employee> listofEmployees = hemp1
						.readAllEmployeesFromDB();

				for (Employee eachEmployee : listofEmployees) {
					System.out.println(eachEmployee.getEmployeeId() + " | "
							+ eachEmployee.getLastName() + " | "
							+ eachEmployee.getFirstName() + " | "
							+ eachEmployee.getHouseNo() + "|"
							+ eachEmployee.getStreet() + "|"
							+ eachEmployee.getCity() + "|"
							+ eachEmployee.getState() + "|"
							+ eachEmployee.getCountry() + "|"
							+ eachEmployee.getMobileNo() + "|"
							+ eachEmployee.getEmail());

				}
				break;

			case 3:
				HandleAdmins hadm1 = new HandleAdmins();
				List<Administrator> listofAdmins = hadm1
						.readAllAdminsFromDB();

				for (Administrator eachAdmin : listofAdmins) {
					System.out.println(eachAdmin.getAdminId() + " | "
							+ eachAdmin.getLastName() + " | "
							+ eachAdmin.getFirstName() + " | "
							+ eachAdmin.getHouseNo() + "|"
							+ eachAdmin.getStreet() + "|"
							+ eachAdmin.getCity() + "|"
							+ eachAdmin.getState() + "|"
							+ eachAdmin.getCountry() + "|"
							+ eachAdmin.getMobileNo() + "|"
							+ eachAdmin.getEmail());

				}
				break;

			case 4:
				o++;
				System.out.println("");
				break;
			default:
				break;
			}

		}

	}

}
